import {
    GetPayConfig,
    SetPayConfig,
    GetStorePrincipalInfo,
} from '@/services/weapp/paysetting/paysetting';
import {catchException} from '@/utils/utils';
export default {
    namespace: 'paysetting',

    state: {
        info:{},
        StoreInfo:[],
    },
    effects: {
        *GetPayConfig({param, callBack}, {call, put}) {
            const data = yield call(GetPayConfig, param);
            yield catchException(function* (){
              if(data.Code === 0) {
                yield put({
                    type: 'PayConfig',
                    info: data.Data
                });
                callBack && callBack.success(data);
            } else {
                callBack && callBack.error(data)
            }
            })

        },
        *SetPayConfig({param, callBack}, {call, put}) {
            const data = yield call(SetPayConfig, param);
            yield catchException(function* (){
              if(data.Code === 0) {
                callBack && callBack.success(data);
            } else {
                callBack && callBack.error(data)
            }
            })

        },
        *GetStorePrincipalInfo({param, callBack}, {call, put}) {
            const data = yield call(GetStorePrincipalInfo, param);
            yield catchException(function* (){
              if(data.Code === 0) {
                yield put({
                    type: 'StorePrincipalInfo',
                    info: data.Data
                });
            } else {
                callBack && callBack.error(data)
            }
            })

        },
    },
    reducers: {
        StorePrincipalInfo(state, {info}) {
            return {
                ...state,
                StoreInfo: info,
            };
        },
        PayConfig(state, {info}) {
            return {
                ...state,
                info: info,
            };
        },
    }
}
